package com.madinatek.designproject.client;

import java.io.File;
import java.io.FilenameFilter;

public class AlgorithmPackage {
	public String AlgorithmName;

	public String FileName;
	public String FullFileName;

	public String toString() {
		return AlgorithmName;
	}

	public static AlgorithmPackage[] search() {
		AlgorithmPackage[] packages = null;
		try {
			
			File dir = new File("algorithm_packages");

			FilenameFilter filter = new FilenameFilter() {
				public boolean accept(File dir, String name) {
					return name.endsWith(".tar");
				}
			};

			String files[] = dir.list(filter);
			if (files != null) {
				packages = new AlgorithmPackage[files.length];

				for (int i = 0; i < files.length; i++) {
					packages[i] = new AlgorithmPackage();
					String algorithmname = files[i].replace('_', ' ');
					int index = algorithmname.lastIndexOf(".tar");
					
					packages[i].AlgorithmName = algorithmname.substring(0, index);
					packages[i].FullFileName = dir.getCanonicalPath()
							+ File.separatorChar + files[i];
					packages[i].FileName = files[i];
					//System.out.println(packages[i].FileName);
				}
			}
		} catch (Exception ex) {
		}
		
		return packages;
	}
}
